﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Enlightener.Engine.Structs__Enums___Interfaces;
using Enlightener.Engine.Utils;
using Mono.Cecil;
using de4dot.blocks.cflow;

namespace Enlightener.Engine.Deobfuscator.Tasks.Common
{
    class MethodCleaner : DeobfuscationTask
    {
        public MethodCleaner(AssemblyDefinition asmDef)
            : base(asmDef)
        {
            RoutineDescription = "Strip all control flow obfuscation";
        }

        [DeobfuscationPhase(1, "Deobfuscate control flow")]
        public static bool Phase1()
        {
            var deobf = new CflowDeobfuscator();
            var counter = 0;

            foreach (var mDef in AsmDef.FindMethods(m => true)){
                deobf.deobfuscate(mDef);
                //Logger.VLog("Cleaned: " + mDef.Name);
                counter++;
            }

            Logger.VSLog(string.Format("{0} methods cleaned...", counter));

            return true;
        }
    }
}
